package com.ronghui.cash.util;

public class CalcRateUtil {

	Double interestRate; // 日利率
	Double money; // 金额
	Integer period; // 期数
	Integer day; // 借款天数
	Double overdueRate; // 逾期利率

	/**
	 *
	 * @param interestRate
	 * @param money
	 * @param period
	 * @param overdueRate
	 */
	public CalcRateUtil(Double interestRate, Double money, Integer period, Double overdueRate, Integer day) {
		this.interestRate = Util.div(interestRate, 100);
		this.money = money;
		this.period = period;
		this.overdueRate = Util.div(overdueRate, 100);
		this.day = day;
	}

	/**
	 * 每期应还金额
	 * @return
	 */
	public Double getEachReturnMoney() {
		return Util.div(money, period);
	}


	/**
	 * 获取借款总利息（手续费）
	 * @return
	 */
	public Double getInterest() {
		return Util.mul(Util.mul(interestRate,money),day);
	}

	/**
	 * 获取实际到账金额
	 */
	public Double getActualMoney(){
		return Util.sub(money, getInterest());
	}

	/**
	 * 获取逾期罚款金额
	 * @param day
	 * @return
	 */
	public Double getPenalty(int day) {
		return Util.mul(Util.mul(money, overdueRate), day);
	}

	/**
	 *
	 * @return 获得本金中的最后几分钱
	 */
	public Double getLastLittleMoney() {
		Double a = Util.double2Double(Util.div(money, period));
		Double b = Util.double2Double(Util.mul(a, period));
		Double c = Util.double2Double(Util.sub(money, b));
		return c;
	}
}
